window.onload = function () {
	/*可视区宽度*/
	var clientWidth = document.documentElement.clientWidth;
	
	/*广告变量*/
	var oAdv = document.getElementsByClassName("advert")[0];
	var oAdvUl = oAdv.getElementsByTagName("ul")[0];
	var aAdvLi = oAdvUl.getElementsByTagName("li");
	
	for (var i = 0; i < aAdvLi.length; i++) {
		aAdvLi[i].style.width = clientWidth + "px";
	}
	
	var advIndex = 1;
	function advert() {
		if (aAdvLi.length == 1) return;
		
		startMove(oAdvUl, {left: advIndex * -aAdvLi[0].offsetWidth});
		
		if (advIndex == aAdvLi.length - 1) {
			advIndex = -1;
		}
		
		advIndex++;
	}
	
	setInterval(advert, 5000);
}



/*获取样式*/
function getStyle(obj, name) {
	if(obj.currentStyle) {
		if(name == "opacity") {
			return Math.round(parseFloat(obj.currentStyle[name]) * 100);
		} else {
			return parseInt(obj.currentStyle[name]);
		}
	} else {
		if(name == "opacity") {
			return Math.round(parseFloat(getComputedStyle(obj, false)[name]) * 100);
		} else {
			return parseInt(getComputedStyle(obj, false)[name]);
		}
	}
}

/*获取class*/
function getByClass(oParent, sClass) {
	var aEle = oParent.getElementsByTagName("*");
	var aResult = [];

	for(var i = 0; i < aEle.length; i++) {
		if(aEle[i].className == sClass) {
			aResult.push(aEle[i]);
		}
	}

	return aResult;
}

/*运动框架*/
function startMove(obj, json, fnEnd) {
	clearInterval(obj.timer);

	obj.timer = setInterval(function() {
		var bStop = true;

		for(var attr in json) {
			var cur = getStyle(obj, attr);
			var speed = (json[attr] - cur) / 6;
			speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);

			if(cur != json[attr]) {
				bStop = false;
			}

			if(attr == "opacity") {
				obj.style.filter = "alpha(opacity = " + (cur + speed) + ")";
				obj.style[attr] = (cur + speed) / 100;
			} else {
				obj.style[attr] = cur + speed + "px";
			}
		}

		if(bStop) {
			clearInterval(obj.timer);

			if(fnEnd) fnEnd();
		}
	}, 30);
}

/*获取鼠标坐标*/
function getPos(ev) {
	var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
	var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;

	return {
		x: ev.clientX + scrollLeft + "px",
		y: ev.clientY + scrollTop + "px"
	};
}

/*事件绑定*/
function myAddEvent(obj, ev, fn) {
	if(obj.attachEvent) {
		obj.attachEvent("on" + ev, fn);
	} else {
		obj.addEventListener(ev, fn, false);
	}
}